%input data form : index F_X1(head) F_X2(tail) L_X1(head) L_X2(tail) F_X1(after scaling) F_X2(afterscaling) L_X1(after scaling) L_X2(afterscaling)
cd('D:\working space\GPT10\GPT10_chain_length_variation_Jia20160301');
file_path=dir('GPT10*N=5*.txt');
n_file=size(file_path,1);
R=112.3; % radius of track (mm)

for i=1:1,
    read_in_data=dlmread(file_path(i).name,'\t',1,0);
    read_in_data(read_in_data==-999)=NaN;
    read_in_data(:,[6:9])=unwrap(read_in_data(:,[6:9]));
    chain_length=[read_in_data(:,1) R*abs(read_in_data(:,6)-read_in_data(:,7)) R*abs(read_in_data(:,8)-read_in_data(:,9))];
    f=figure;
    subplot(1,2,1)
    %[y,x]=hist(chain_length(:,2),[11:0.5:25]);
    [y,x]=hist(chain_length(2:end,3)-chain_length(1:end-1,3),[-3:0.5:3]);
    output=[transpose(x) transpose(y)];
    subplot(1,2,2)
    hist(chain_length(2:end,3)-chain_length(1:end-1,3),[-3:0.5:3])
    std(chain_length(~isnan(chain_length(:,2)),2))
    std(chain_length(~isnan(chain_length(:,3)),3))
end
g=figure;
smooth_chain=smooth(chain_length(2200:2900,3),5);
plot(2200:2900,chain_length(2200:2900,3));hold on
plot(2200:2900,smooth_chain);
    